<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<table id="tab">

</table>


<!-- 2级模态框-->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">生产派工</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="container"
                     style="padding-bottom:10px ;box-shadow: rgba(144,146,154,0.46) 5px 5px; background-color: whitesmoke;text-align: center">
                    <div>
                        <h2>派工单审核</h2>
                    </div>
                    <div class="">
                        <form>
                            <div class="form-row">
                                <div class="col">
                                    派工单编号：<span id="manufactureId1"></span>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="col">
                                    产品编号： <span id="productId1"></span>
                                </div>
                                <div class="col">
                                    产品名称:<span id="productName1"></span>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="col">
                                    数量： <span id="amount1"></span>
                                </div>
                                <div class="col">
                                    工序制订人:<span id="designer1"></span>
                                </div>
                            </div>

                            <table id="table1" style="width: 100%; margin: 20px 0px">
                                <thead>
                                <tr style="background-color: #a4efef;">
                                    <th>序号</th>
                                    <th>工序名称</th>
                                    <th>工序编号</th>
                                    <th>工时数</th>
                                    <th>工时成本小计</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>

                            <div class="form-row">
                                <div class="col">
                                    工时总成本： <span id="labourCostPriceSum1"></span>
                                </div>
                                <div class="col">
                                    物料总成本:
                                    <span id="moduleCostPriceSum1"></span>
                                </div>
                            </div>

                            <div class="form-row" >
                                <div class="col">
                                    登记人： <span id="registrant1" ></span>
                                </div>
                                <div class="col">
                                    登记时间:
                                    <span id="registrationTime1"></span>
                                </div>
                            </div>

                            <div class="form-row" >
                                <div class="col">
                                    审核人： <span id="checker1" ></span>
                                </div>
                                <div class="col">
                                    审核时间:
                                    <span id="checkTime1"></span>
                                </div>
                            </div>
                        </form>
                        <div class="form-row">
                            <div class="col">
                                描述： <span id="productDescribe1"></span>
                            </div>
                        </div>
                        <div style="margin: 20px 0px">
                            备注：
                            <textarea class="form-control" id="remark1" readonly></textarea>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1"
                                   value="s001-1" checked>
                            <label class="form-check-label" for="exampleRadios1">
                                通过
                            </label>
                        </div>
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2"
                                   value="s001-2">
                            <label class="form-check-label" for="exampleRadios2">
                                不通过
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button id="SubmissionPreparationSheet" type="button" onclick="DispatchingAudit()" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>


<script>
    $(function () {
        $("#tab").bootstrapTable({
            method: "post",
            contentType: "application/json",
            striped: true,
            pageNumber: 1,
            pageSize: 5,
            pagination: true,
            sidePagination: 'server',
            pageList: [1, 3, 5, 10],
            url: "/workOrder/queryProcedure",
            queryParams: function (params) {
                return {
                    // 计算页号(当前页)
                    pageNumber: (params.offset / params.limit) + 1,
                    // 计算页大小
                    pageSize: params.limit
                }
            },
            columns: [
                {title: '派序号编号', field: 'manufactureId', align: 'center',},
                {title: '产品编号', field: 'productId', align: 'center',},
                {title: '产品名称', field: 'productName', align: 'center',},
                {title: '数量', field: "amount", align: 'center'},
                {title: '登记时间', field: "registerTime", align: 'center'},
                {
                    title: '审核', field: 'on',
                    formatter: function (value, row, index) {
                        return "<button class='btn btn-primary'  data-toggle=\"modal\"  data-target=\"#exampleModal\" onclick='viewAudit("+row.manufactureId+")' >审核</button>";
                    }

                }
            ]
        })
    })

    function viewAudit(id){
        $.ajax({
            type: "post",
            data: "id=" + id,
            url: "/workOrder/viewAudit",
            success: function (data) {
                $("#manufactureId1").text(data.manufactureId);
                $("#productId1").text(data.productId);
                $("#productName1").text(data.productName);
                $("#amount1").text(data.amount);
                $("#designer1").text(data.designer);
                $("#labourCostPriceSum1").text(data.labourCostPriceSum);
                $("#moduleCostPriceSum1").text(data.moduleCostPriceSum);
                $("#registrant1").text(data.register)
                $("#registrationTime1").text(data.registerTime);
                $("#checkTime1").text(getTime());
                $("#productDescribe1").text(data.productDescribe);
                $("#remark1").text(data.remark);
                $("#table1 tbody").html("");
                var procedure=data.procedureList;
                for (let i=0;i<procedure.length;i++){
                    $("#table1 tbody").append("<tr>" +
                        "<td>"+procedure[i].id+"</td>" +
                        "<td>"+procedure[i].procedureName+"</td>" +
                        "<td>"+procedure[i].procedureId+"</td>" +
                        "<td>"+procedure[i].labourHourAmount+"</td>" +
                        "<td>"+procedure[i].subtotal+"</td>" +
                        "</tr>")
                }
            }
        })
    }
    $(function (){
        $.ajax({
            type: "post",
            url:"/plan/queryRegistrant",
            success:function (data){
                $("#checker1").text(data.loginId);
            }
        })
    })


    function getTime() {
        var d = new Date();
        var year = d.getFullYear()  //获取年
        var month = d.getMonth() + 1;  //获取月，从 Date 对象返回月份 (0 ~ 11)，故在此处+1

        var days = d.getDate() //获取日期
        var hour = d.getHours()   //获取小时
        var minute = d.getMinutes()  //获取分钟
        var second = d.getSeconds()   //获取秒
        return year + "/" + month + "/" + days + " " + hour + ":" + minute + ":" + second
    }

    function DispatchingAudit(){
        $.ajax({
            type:"post",
            data: JSON.stringify({
                checkTag:$(".form-check-input:checked").val(),
                checker:$("#checker1").text(),
                checkTime:$("#checkTime1").text(),
                manufactureId:$("#manufactureId1").text()
            }),
            contentType: "application/json",
            url:"/workOrder/DispatchingAudit",
            success:function (data){
                if (data>0){
                    alert("审核成功");
                    $("#exampleModal").modal("hide");
                    $("#tab").bootstrapTable("refresh");
                }else{
                    alert("审核失败");
                }
            }
        })
    }
</script>




</body>
</html>